name: Deploy to staging

on:
  push:
    branches:
      - stable
      - staging

jobs:
  build:
    # Build our docker images based on our bake file
    runs-on: [self-hosted, dev]
    steps:
      - uses: actions/checkout@v2
      # Build the bakefile and push
      - uses: ./.github/actions/docker-bake

  trigger_deploy:
    # Trigger private repo to deploy to staging and dev related environments
    runs-on: [self-hosted, dev]
    needs: [build]
    strategy:
      matrix:
        environment: [staging, hackathon, dev, alpha-dev]
    environment:
      name: ${{ matrix.environment }}
    steps:
      - uses: FranzDiebold/github-env-vars-action@v2
      - uses: convictional/trigger-workflow-and-wait@v1.6.5
        with:
          owner: mindsdb
          repo: INTERNAL-mindsdb-build-deploy-to-kubernetes
          github_token: ${{ secrets.REPO_DISPATCH_PAT_TOKEN }}
          workflow_file_name: deploy-dev.yml
          ref: master
          client_payload: '{"image-tag-prefix": "${{ env.CI_SHA }}", "deploy-env": "${{ matrix.environment }}"}'
